package com.cslg.questionnaires.service;

import com.cslg.questionnaires.mapper.QuestionFormMapper;
import com.cslg.questionnaires.utils.ServiceMessageBuilder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CheckFormService {
    @Resource
    QuestionFormMapper questionFormMapper;

    public HashMap<String, Object> getAllForm(int userId,String userType,int page){
        List<Map> forms = questionFormMapper.getAllFormByUid_type(userId,userType);
        if (forms.size() == 0){
            return ServiceMessageBuilder
                    .buildMessage(404,"你还未收到任何填写的表单！",null);
        }else {
            return ServiceMessageBuilder
                    .buildMessage(200,"success",forms);
        }
    }

    public HashMap<String,Object> getFormByQuestionId(int questionId,int userId,String userType,int page){
        List<Map> forms = questionFormMapper.getFormByQuestionId(questionId,userId,userType);
        if (forms.size() == 0){
            return ServiceMessageBuilder
                    .buildMessage(404,"此问卷未收到任何表单！",null);
        }else {
            return ServiceMessageBuilder
                    .buildMessage(200,"success",forms);
        }
    }
}
